package com.DMS.mapper;


import com.DMS.dao.Admin;
import com.DMS.dao.Dorms;
import com.DMS.dao.Students;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface UserMapper {

    @Select("select * from admin where username = #{username} and password = #{password}")
    public Admin findByUsernameAndPassword(String username, String password);

    @Insert("insert into admin(username,password) values(#{username},#{password})")
    int insertAdmin(Admin admin);

    @Update("update admin set password = #{password} where username = #{username}")
    int updatePassword(@Param("username") String username,@Param("password") String password);

    @Select("select * from admin")
    List<Admin> findAll();

    @Delete("DELETE FROM admin WHERE id = #{id};")
    int deleteAdmin(int id);

    @Update("UPDATE admin SET username=#{username},password=#{password} WHERE id = #{id}")
    int updateAdmin(Admin admin);


    @Select("SELECT * FROM students")
    List<Students> findAllStudents();

    @Insert("INSERT INTO students(name, age, sex, major, classname, dorm) VALUES(#{name}, #{age}, #{sex}, #{major}, #{classname}, #{dorm})")
    int insertStudent(Students student);

    @Update("UPDATE students SET name=#{name}, age=#{age}, sex=#{sex}, major=#{major}, classname=#{classname}, dorm=#{dorm} WHERE id = #{id}")
    int updateStudent(Students student);

    @Delete("DELETE FROM students WHERE id = #{id}")
    int deleteStudent(int id);

    @Select("SELECT * FROM students WHERE name LIKE #{keyword} OR classname LIKE #{keyword} OR major LIKE #{keyword} OR dorm LIKE #{keyword}")
    List<Students> searchStudents(String keyword);



    @Select("SELECT * FROM dorms")
    List<Dorms> findAllDorms();

    @Insert("INSERT INTO dorms(dormNumber, capacity, occupied, facilities, building, floor) VALUES(#{dormNumber}, #{capacity}, #{occupied}, #{facilities}, #{building}, #{floor})")
    int insertDorm(Dorms dorm);

    @Update("UPDATE dorms SET dormNumber=#{dormNumber}, capacity=#{capacity}, occupied=#{occupied}, facilities=#{facilities}, building=#{building}, floor=#{floor} WHERE id = #{id}")
    int updateDorm(Dorms dorm);

    @Delete("DELETE FROM dorms WHERE id = #{id}")
    int deleteDorm(int id);

    @Select("SELECT * FROM dorms WHERE dormNumber LIKE #{keyword} OR building LIKE #{keyword} OR floor LIKE #{keyword}")
    List<Dorms> searchDorms(String keyword);

    @Select("SELECT * FROM dorms WHERE id = #{id}")
    Dorms getDormById(int id);

}

